Skip to content

Lazy loaded Twig Extension #123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

qdequippe
Copy link

@qdequippe qdequippe force-pushed the mercure-twig-runtime branch from d53af01 to 43f8bd4 Compare June 16, 2025 10:20
Copy link
Member

@GromNaN GromNaN left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing a public method from a class is a breaking change, but I think we can make it of the next 0.minor version.

The extension attributes added in Twig 3.21.0 allows to create lazy extension with a single class. I recommend this approach.

The MercureBundle must also be updated to enable autoconfiguration (or add both twig.attribute_extension and twig.runtime tags): https://github.com/symfony/mercure-bundle/blob/main/src/DependencyInjection/MercureExtension.php#L270-L274

*
* @return string The URL of the hub with the appropriate "topic" query parameters (if any)
*/
public function mercure($topics = null, array $options = []): string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could keep this function in this class and use the #[TwigFunction] attribute to make this extension lazy.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@qdequippe qdequippe force-pushed the mercure-twig-runtime branch from 8b3606b to 6cdd947 Compare August 15, 2025 17:13
@qdequippe qdequippe force-pushed the mercure-twig-runtime branch from 6cdd947 to 3000654 Compare August 15, 2025 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants